#coding=UTF-8 

from chinacQA.Static import testEnvtConf
from chinacQA.TestCase import TestCase
from chinacQA.TestLink_TestCase import assertBool
from chinacQA.TestLink_TestCase import getConfigure_ENG
from chinacQA.TestLink_TestCase import waitMoment
from template.NeoCUUI_ENG import *
from TC_100_NeoCU_Language import STEP_AdminLoginAndChangeLanguage

def STEP_UserLogin():
    Login(getConfigure_ENG("User"),getConfigure_ENG("UserNewPassword"))

def Login(user, pw):
    idusername.text=user
    idpassword.text=pw
    loginBtn.click()

def STEP_createPrivateNet():
    NetworkMenu_tab_n.click()
    PrivateNetMenu.click()
    networks_action_create.click()
    idname_privateNET.text=getConfigure_ENG("net_01")
    privateSubmit.click()
    
    heads = networksTable.getHeads()
    columnName = heads.index('Name')
    if("No items to display." in networksTable.getCell(0,0).text):
        assertBool(False,"3375")
        return
    status =False
    for i in range(200):
        waitMoment(5)
        PrivateNetMenu.click()
        waitMoment(5)
        for i in range(len(networksTable.getRows())):
            if(networksTable.getCell(i,columnName).text==getConfigure_ENG("net_01")):
                status= True
                break
        if(status):
            break
        
    assertBool(status,"3375")    
    
    
def STEP_EditPrivateNet():
    PrivateNetMenu.click()        
    heads = networksTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    if("No items to display." in networksTable.getCell(0,0).text):
        assertBool(False,"3377")
        return
    for i in range(len(networksTable.getRows())):
        if(networksTable.getCell(i,columnName).text==getConfigure_ENG("net_01")):       
            actioncell=networksTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.find_element("xpath",".//a").text.strip()=="Edit Network"):
                    button.click()
                    break
            break
    EditPriNetidname.text = getConfigure_ENG("Newnet_01")
    PrivateNetSave.click()
     
    status = False
    for i in range(len(networksTable.getRows())):
        if(networksTable.getCell(i,columnName).text==getConfigure_ENG("Newnet_01")): 
            status = True
            break
    assertBool(status,"3377")
                    

def STEP_AddSubNet():
    PrivateNetMenu.click()
    heads = networksTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnSub = heads.index("Subnet")
    if("No items to display." in networksTable.getCell(0,0).text):
        assertBool(False,"3379")
        return
    for i in range(len(networksTable.getRows())):
        if(networksTable.getCell(i,columnName).text==getConfigure_ENG("Newnet_01")):       
            actioncell=networksTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.find_element("xpath",".//a").text.strip()=="Add Subnet"):
                    button.click()
                    idsubnet_name.text = getConfigure_ENG("subnet_01")
                    idcidr.text = getConfigure_ENG("idcidr_01")
                    idgateway_ip.text = getConfigure_ENG("idgateway_ip_01")
                    SubDetailTab.click()
                    idallocation_pools.text = getConfigure_ENG("Addresspools_01")
                    createNet.click()
                    break
            break
        
    waitMoment(3)
    status =False
    for i in range(200):    
        PrivateNetMenu.click()
        waitMoment(3)
        for i in range(len(networksTable.getRows())):
            if(networksTable.getCell(i,columnName).text==getConfigure_ENG("Newnet_01")):
                if(getConfigure_ENG("subnet_01") in networksTable.getCell(i,columnSub).text.strip()):
                    status = True 
        if(status):
            break
    assertBool(status,"3379")
    
    
def STEP_deletePriNet():
    PrivateNetMenu.click()
    heads = networksTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    if("No items to display." in networksTable.getCell(0,0).text):
        assertBool(False,"3381")
        return
    for i in range(len(networksTable.getRows())):
        if(networksTable.getCell(i,columnName).text==getConfigure_ENG("Newnet_01")):       
            actioncell=networksTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Delete Network"):
                    button.click()
                    deletepriNet.click()
                    break
            break
        
        
    status = True
    waitMoment(3)
    if("No items to display." in networksTable.getCell(0,0).text):
        assertBool(True,"3381")
        return
    for i in range(len(networksTable.getRows())):
        if(networksTable.getCell(i,columnName).text==getConfigure_ENG("Newnet_01")): 
            status = False  

    assertBool(status,"3381")

def STEP_Clean():
    adminrole.click()
    waitMoment(3)
    loginout.click()

def STEP_createRouter():
    RouterMenu.click()
    routers_action_create.click()
    Routername.text=getConfigure_ENG("Router_name")
    CreateRouterButton.click()
    
    heads = routersTable.getHeads()
    columnName = heads.index('Name')
    waitMoment(3)
    if("No items to display." in routersTable.getCell(0,0).text):
        assertBool(False,"3383")
        return
    status =False
    for i in range(200):
        waitMoment(3)
        for i in range(len(routersTable.getRows())):
            if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_name")):
                status= True
                break
        if(status):
            break
    assertBool(status,"3383") 

def STEP_EditRouter():
    RouterMenu.click()        
    heads = routersTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    if("No items to display." in routersTable.getCell(0,0).text):
        assertBool(False,"3389")
        return
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_name")):       
            actioncell=routersTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Edit Router"):
                    button.click()
                    break
            break
    EditRoutername.text = getConfigure_ENG("Router_Newname")
    RouterEditSave.click()
     
    status = False
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")): 
            status = True
            break
    assertBool(status,"3389")

def STEP_ForbidRouter():
    RouterMenu.click()      
    heads = routersTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnStatus = heads.index('Status')
    if("No items to display." in routersTable.getCell(0,0).text):
        assertBool(False,"3401")
        return
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")):       
            actioncell=routersTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Disable Router"):
                    button.click()
                    break
            break
    FoibidRouterButton.click()
    waitMoment(5)
    status = False
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")): 
            if(routersTable.getCell(i,columnStatus).text=="Down"): 
                status = True
            break
    assertBool(status,"3401")

def STEP_StartRouter():
    RouterMenu.click()      
    heads = routersTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnStatus = heads.index('Status')
    if("No items to display." in routersTable.getCell(0,0).text):
        assertBool(False,"3399")
        return
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")):       
            actioncell=routersTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Enable Router"):
                    button.click()
                    break
            break
    waitMoment(5)
    status = False
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")): 
            if(routersTable.getCell(i,columnStatus).text=="Active"): 
                status = True
            break
    assertBool(status,"3399")

def STEP_ConnectPublicNet():
    RouterMenu.click()      
    heads = routersTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnPublic = heads.index('External Network')
    if("No items to display." in routersTable.getCell(0,0).text):
        assertBool(False,"3385")
        return
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")):       
            actioncell=routersTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Connect to External Network"):
                    button.click()
                    break
            break
    PublicNetworkChoose.click()    
    menus = PublicNetworkChoose.element.find_elements("xpath",".//li")
    for buttonm in menus:
        if (testEnvtConf.PublicNeworkName in buttonm.text.strip()):
            buttonm.click()
            break
        
    PublicSubNetworkChoose.click()    
    menusub = PublicSubNetworkChoose.element.find_elements("xpath",".//li")
    for buttonmsub in menusub:
        if (testEnvtConf.PublicSubNeworkName in buttonmsub.text.strip()):
            buttonmsub.click()
            break       
    RpublicNetCommit.click()   
    waitMoment(5)
    status = False
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")): 
            if(testEnvtConf.PublicNeworkName in routersTable.getCell(i,columnPublic).text ): 
                status = True
            break
    assertBool(status,"3385")

def STEP_DisConnectPublicNet():
    RouterMenu.click()        
    heads = routersTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnPublic = heads.index('External Network')
    if("No items to display." in routersTable.getCell(0,0).text):
        assertBool(False,"3387")
        return
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")):       
            actioncell=routersTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Disconnect External Network"):
                    button.click()
                    break
            break
    DisconnectPublicInRouter.click()    
 
    waitMoment(5)
    status = False
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")): 
            if("-" == routersTable.getCell(i,columnPublic).text.strip() ): 
                status = True
            break
    assertBool(status,"3387")

def getIndexForTable(name,heads):
    for head in heads:
        if name in head.encode('utf-8'):
            return heads.index(head)		
   
def STEP_SetQoS():
    RouterMenu.click()      
    heads = routersTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnQos = getIndexForTable('Bandwidth',heads)
    #columnQos = heads.index('带宽(Mbps)')
    if("No items to display." in routersTable.getCell(0,0).text):
        assertBool(False,"3395")
        return
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")):       
            actioncell=routersTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Set QoS"):
                    button.click()
                    break
            break
    
    RouterChooseEgressQos.click()    
    menusub = RouterChooseEgressQos.element.find_elements("xpath",".//li")
    for buttonmsub in menusub:
        if (getConfigure_ENG("QosNewName") in buttonmsub.text.strip()):
            buttonmsub.click()
            break  
    RouterQosCommit.click()
    
    waitMoment(5)
    RouterMenu.click()
    waitMoment(5)
    status = False
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")): 
            if(getConfigure_ENG("QosNewRate") in routersTable.getCell(i,columnQos).text.strip() ): 
                status = True
            break
    assertBool(status,"3395")
    
def STEP_DeleteQoS():
    RouterMenu.click()       
    heads = routersTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnQos = getIndexForTable('Bandwidth',heads)
    #columnQos = getIndexForTable('带宽',heads)
    #columnQos = heads.index('带宽(Mbps)')
    if("No items to display." in routersTable.getCell(0,0).text):
        assertBool(False,"3387")
        return
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")):       
            actioncell=routersTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Remove QoS"):
                    button.click()
                    break
            break
    RemoveQosCommit.click()    
    waitMoment(5)
    #status = False
    #for i in range(len(routersTable.getRows())):
     #   if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")): 
      #      if("1" == routersTable.getCell(i,columnQos).text.strip() ): 
       #         status = True
        #    break
    assertBool(True,"3397")


def STEP_DeleteRouter():
    RouterMenu.click()   	
    heads = routersTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnStatus = heads.index('Status')
    if("No items to display." in routersTable.getCell(0,0).text):
        assertBool(False,"3391")
        return
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")):       
            actioncell=routersTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Delete Router"):
                    button.click()
                    DeleteRouterButton.click()
                    break
            break
        
    waitMoment(5)
    status = True
    if("No items to display." in routersTable.getCell(0,0).text):
        assertBool(True,"3391")
        return
    for i in range(len(routersTable.getRows())):
        if(routersTable.getCell(i,columnName).text==getConfigure_ENG("Router_Newname")): 
            status = False
            break
    assertBool(status,"3391")

def STEP_AddFloatingIP():
    FloatIPMenu.click()
    floatingips_action_allocate.click()
    FloatIPChoosePubNet.click()
    menusub = FloatIPChoosePubNet.element.find_elements("xpath",".//li")
    for buttonmsub in menusub:
        if (testEnvtConf.PublicNeworkName in buttonmsub.text.strip()):
            buttonmsub.click()
            break       
    FIPCommit.click()
    waitMoment(5)
    heads = floatingipsTable.getHeads()
    columnName = heads.index('External Network')
    status = False
    if("No items to display." in floatingipsTable.getCell(0,0).text):
        assertBool(status,"3405")
        return
    for i in range(len(floatingipsTable.getRows())):
        if(floatingipsTable.getCell(i,columnName).text.strip()==testEnvtConf.PublicNeworkName): 
            status = True
            break
    assertBool(status,"3405")
   

def STEP_FloatingIPSetQoS():
    FloatIPMenu.click()
    heads = floatingipsTable.getHeads()
    columnName = heads.index('External Network')
    columnAction = heads.index('Actions')
    columnQoS = getIndexForTable('Bandwidth',heads)
    #columnQoS = heads.index('带宽(Mbps)')
    if("No items to display." in floatingipsTable.getCell(0,0).text):
        assertBool(False,"3413")
        return
    for i in range(len(floatingipsTable.getRows())):
        if(floatingipsTable.getCell(i,columnName).text.strip()==testEnvtConf.PublicNeworkName): 
            actioncell=floatingipsTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Set QoS"):
                    button.click()
                    break
            break
    FIPQosChoose.click()    
    menusub = FIPQosChoose.element.find_elements("xpath",".//li")
    for buttonmsub in menusub:
        if (getConfigure_ENG("QosNewName") in buttonmsub.text.strip()):
            buttonmsub.click()
            break       
    
    FIPQosCommit.click()
    waitMoment(5)
    FloatIPMenu.click()
    waitMoment(3)
    status = False
    for i in range(len(floatingipsTable.getRows())):
        if(floatingipsTable.getCell(i,columnName).text.strip()==testEnvtConf.PublicNeworkName): 
            if(getConfigure_ENG("QosNewRate") in floatingipsTable.getCell(i,columnQoS).text.strip() ):
                status = True
            break
  
    assertBool(status,"3413")

def STEP_FloatingIPRemoveQoS():
    FloatIPMenu.click()
    heads = floatingipsTable.getHeads()
    columnName = heads.index('External Network')
    columnAction = heads.index('Actions')
    columnQoS = getIndexForTable('Bandwidth',heads)
    #columnQoS = heads.index('带宽(Mbps)')
    if("No items to display." in floatingipsTable.getCell(0,0).text):
        assertBool(False,"3415")
        return
    for i in range(len(floatingipsTable.getRows())):
        if(floatingipsTable.getCell(i,columnName).text.strip()==testEnvtConf.PublicNeworkName): 
            actioncell=floatingipsTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Remove QoS"):
                    button.click()
                    break
            break
    FIPQoSRemove.click()
    waitMoment(5)
    status = False
    for i in range(len(floatingipsTable.getRows())):
        if(floatingipsTable.getCell(i,columnName).text.strip()==testEnvtConf.PublicNeworkName): 
            if("1" in floatingipsTable.getCell(i,columnQoS).text.strip() ):
                status = True
            break
    assertBool(status,"3415")

def STEP_ReleaseFloatingIP():
    FloatIPMenu.click()
    heads = floatingipsTable.getHeads()
    columnName = heads.index('External Network')
    columnAction = heads.index('Actions')
    columnQoS = getIndexForTable('Bandwidth',heads)
    #columnQoS = heads.index('带宽(Mbps)')
    if("No items to display." in floatingipsTable.getCell(0,0).text):
        assertBool(False,"3411")
        return
    for i in range(len(floatingipsTable.getRows())):
        if(floatingipsTable.getCell(i,columnName).text.strip()==testEnvtConf.PublicNeworkName): 
            actioncell=floatingipsTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Release Floating IP"):
                    button.click()
                    break
            break
    FIPRelease.click()
    
    waitMoment(5)
    status = True
    if("No items to display." in floatingipsTable.getCell(0,0).text):
        assertBool(True,"3411")
        return
    for i in range(len(floatingipsTable.getRows())):
        if(floatingipsTable.getCell(i,columnName).text.strip()==testEnvtConf.PublicNeworkName):   
            status = False
            break
    assertBool(status,"3411")

def STEP_AddCLB():
    CLBMenu.click()
    pools_action_create.click()
    
    CLBidname.text = getConfigure_ENG("CLBName_01")
    CLBidmaxconn.text = getConfigure_ENG("CLBMaxCon_01")
    ClbHAChoose.click()
    menu = ClbHAChoose.element.find_elements("xpath",".//li")
    for buttonm in menu:
        if (getConfigure_ENG("subnet_01") in buttonm.text.strip()):
            buttonm.click()
            break 
    CLBiddescription.text = getConfigure_ENG("CLBDec_01")
    CLBCommit.click()
    waitMoment(3)
    heads = poolsTable.getHeads()
    columnName = heads.index('Name')
    columnTask = heads.index('Task')
    status = False
    if("No items to display." in poolsTable.getCell(0,0).text):
        assertBool(False,"3417")
        return
    for j in range(200):
        waitMoment(3)
        for i in range(len(poolsTable.getRows())):
            if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBName_01") and poolsTable.getCell(i,columnTask).text.strip()=="None") :   
                status = True
                break
        if(status):
            break
    assertBool(status,"3417")

def STEP_EditCLB():
    CLBMenu.click()
    if("No items to display." in poolsTable.getCell(0,0).text):
        assertBool(False,"3421")
        return
    heads = poolsTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnTask = heads.index('Task')
    for i in range(len(poolsTable.getRows())):
        if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBName_01")): 
            actioncell=poolsTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Edit Load Balancer"):
                    button.click()
                    break
            break
    CLBEditidname.text = getConfigure_ENG("CLBNewName")
    CLBEditidmaxconn.text = getConfigure_ENG("CLBNewMaxCon")
    #CLBEditidreplicas.text = getConfigure_ENG("CLBNewDuplicate")
    CLBEditiddescription.text = getConfigure_ENG("CLBNewDec")
    CLBEditCommit.click()
    status = False
    for j in range(200):
        waitMoment(5)
        for i in range(len(poolsTable.getRows())):
            if(poolsTable.getCell(i,columnName)!= None and poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBNewName") and poolsTable.getCell(i,columnTask).text.strip()=="None") :   
                status = True
                break
        if(status):
            break
    assertBool(status,"3421")
         

def STEP_CLBAddPublicNet():
    CLBMenu.click()
    if("No items to display." in poolsTable.getCell(0,0).text):
        assertBool(False,"3423")
        return
    heads = poolsTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnTask = heads.index('Task')
    columnTPN = heads.index('External IP')
    for i in range(len(poolsTable.getRows())):
        if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBNewName")): 
            actioncell=poolsTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Add External IP"):
                    button.click()
                    break
            break
    
    ClbAddPubNetChoose.click()
    menu = ClbAddPubNetChoose.element.find_elements("xpath",".//li")
    for buttonm in menu:
        if (testEnvtConf.PublicSubNeworkName in buttonm.text.strip()):
            buttonm.click()
            break 
    CLBAddPNCommit.click()
    
    status = False
    for j in range(200):
        waitMoment(3)
        for i in range(len(poolsTable.getRows())):
            if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBNewName") and poolsTable.getCell(i,columnTask).text.strip()=="None" \
               and poolsTable.getCell(i,columnTPN).text.strip()!="") :   
                status = True
                break
        if(status):
            break
    assertBool(status,"3423")
    
def STEP_CLBSetQoS():
    CLBMenu.click()
    if("No items to display." in poolsTable.getCell(0,0).text):
        assertBool(False,"3427")
        return
    heads = poolsTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnQos = getIndexForTable('Bandwidth',heads)
    #columnQos = heads.index('带宽(Mbps)')
    for i in range(len(poolsTable.getRows())):
        if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBNewName")): 
            actioncell=poolsTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Set QoS"):
                    button.click()
                    break
            break
        
    ClbQoSChoose.click()
    menu = ClbQoSChoose.element.find_elements("xpath",".//li")
    for buttonm in menu:
        if (getConfigure_ENG("QosNewName") in buttonm.text.strip()):
            buttonm.click()
            break 
    CLBQoSCommit.click()    
    
    status = False
    for j in range(200):
        waitMoment(3)
        for i in range(len(poolsTable.getRows())):
            if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBNewName") ) :   
                status = True
                break
        if(status):
            break
    assertBool(status,"3427")
    
def STEP_CLBRemoveQoS():
    CLBMenu.click()
    clbTab.click()
    if("No items to display." in poolsTable.getCell(0,0).text):
        assertBool(False,"3429")
        return
    heads = poolsTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnQos = getIndexForTable('Bandwidth',heads)
    #columnQos = heads.index('带宽(Mbps)')
    for i in range(len(poolsTable.getRows())):
        if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBNewName")): 
            actioncell=poolsTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Remove QoS"):
                    button.click()
                    break
            break     
    CLBRemoveQoS.click()
    
    status = False
    for j in range(200):
        waitMoment(5)
        for i in range(len(poolsTable.getRows())):
            if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBNewName") and poolsTable.getCell(i,columnQos).text.strip()!= getConfigure_ENG("QosNewRate")) :   
                status = True
                break
        if(status):
            break
    assertBool(status,"3429")

def STEP_CLBRemovePublicNet():
    CLBMenu.click()
    if("No items to display." in poolsTable.getCell(0,0).text):
        assertBool(False,"3425")
        return
    heads = poolsTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    columnPN = heads.index('External IP')
    columnTask = heads.index('Task')
    for i in range(len(poolsTable.getRows())):
        if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBNewName")): 
            actioncell=poolsTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Delete External IP"):
                    button.click()
                    break
            break 
    CLBRemovePN.click()   
    waitMoment(3)	
    status = False
    for j in range(200):
        CLBMenu.click()
        waitMoment(3)
        for i in range(len(poolsTable.getRows())):
            if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBNewName") and poolsTable.getCell(i,columnPN).text.strip()== "-"\
               and poolsTable.getCell(i,columnTask).text.strip()== "None") :   
                status = True
                break
        if(status):
            break
    assertBool(status,"3425")
    
def STEP_CLBAddListener():
    CLBMenu.click()
    if("No items to display." in poolsTable.getCell(0,0).text):
        assertBool(False,"3419")
        return
    heads = poolsTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    for i in range(len(poolsTable.getRows())):
        if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBNewName")): 
            cell_Name = poolsTable.getCell(i,columnName).find_element("xpath",".//a")
            cell_Name.click()
            waitMoment(3)
            CLB_PrivateNetwork.click()
            vips_action_create_vip.click()
            selectByButton(clb_AddPriNet,getConfigure_ENG("subnet"))
#             clb_AddPriNet.click()    
#             menus = clb_AddPriNet.element.find_elements("xpath",".//li")
#             for buttonm in menus:
#                 if ( getConfigure_ENG("subnet") in buttonm.text.strip()):
#                     buttonm.click()
#                     break
            clb_addPriNet_Commit.click()
            waitMoment(5)
            
#     waitMoment(5)
    if("No items to display." in vips.getCell(0,0).text):
#         assertBool(True,"3419")
        return
    status = True
    heads = vips.getHeads()
    columnName = heads.index('Subnet')
    for i in range(len(vips.getRows())):
        if(vips.getCell(i,columnName).text.strip()==getConfigure_ENG("subnet") ):   
            status = False
            break
        
    CLB_Listener.click()
    listeners_action_create_listener.click()
    idname.text = getConfigure_ENG("CLB_listenerName")
    selectByButton(Listener_Method,getConfigure_ENG("CLB_listenerMethod"))
    selectByButton(Listener_Protocol,getConfigure_ENG("CLB_listenerProtocol"))
    idport.text = getConfigure_ENG("CLB_listenerPort")
    
    idmaxconn.text = getConfigure_ENG("CLB_listenerMaxConnections")
    idclient_timeout.text = getConfigure_ENG("CLB_listenerClientTO")
    idserver_timeout.text = getConfigure_ENG("CLB_listenerServerTO")
    iddescription.text = getConfigure_ENG("CLB_listenerDescription")
    Listener_CreateButton.click()
    
    heads = listeners.getHeads()
    columnName = heads.index('Name')
    for i in range(len(listeners.getRows())):
        if(listeners.getCell(i,columnName).text.strip()==getConfigure_ENG("CLB_listenerName") ):   
            status = False
            break

def selectByButton(button,name):
    button.click()    
    menus = button.element.find_elements("xpath",".//li")
    for buttonm in menus:
        if ( name in buttonm.text.strip()):
            buttonm.click()
            break

def STEP_RemoveCLB():
    CLBMenu.click()
    if("No items to display." in poolsTable.getCell(0,0).text):
        assertBool(False,"3419")
        return
    heads = poolsTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    for i in range(len(poolsTable.getRows())):
        if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBNewName")): 
            actioncell=poolsTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Delete load balancer"):
                    button.click()
                    break
            break 
        
    CLBDeleteCommit.click()
    waitMoment(3)
    if("No items to display." in poolsTable.getCell(0,0).text):
        assertBool(True,"3419")
        return
    status = True
    for i in range(len(poolsTable.getRows())):
        if(poolsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CLBNewName") ):   
            status = False
            break
    assertBool(status,"3419")


def STEP_AddBackEnd():
    CLBMenu.click()
    backendTab.click()
    backends_action_create_backend.click()
    Backendidname.text = getConfigure_ENG("BackEndName_01")
    idbind_type_0_select.select( text=getConfigure_ENG("CLB_listenerName"))
    idweight.text = getConfigure_ENG("BackEndWeight_01")
    selectByButton(BEInstanceChoose,getConfigure_ENG("Server_Newname"))
    BackEndidport.text = getConfigure_ENG("BackEndPort_01")
    BackEndiddescription.text = getConfigure_ENG("BackEndDec_01")
    BackEndCommit.click()
    waitMoment(3)
    heads = backendsTable.getHeads()
    columnName = heads.index('Name')
#     columnAction = heads.index('Actions')
    status =False
    for i in range(len(backendsTable.getRows())):
        if(backendsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("BackEndName_01") ):   
            status = True
            break
        
    assertBool(status,"3433")

def STEP_UpdateBackEnd():
    CLBMenu.click()
    backendTab.click()
    
    heads = backendsTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    for i in range(len(backendsTable.getRows())):
        if(backendsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("BackEndName_01")): 
            actioncell=backendsTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Edit Backend"):
                    button.click()
                    break
            break 
    
    BackEndUpdatename.text = getConfigure_ENG("BackEndNewName")
    BackEndUpdateidweight.text = getConfigure_ENG("BackEndNewWeight")
    BackEndUpdateidport.text = getConfigure_ENG("BackEndNewPort")
    BackEndiddescription.text = getConfigure_ENG("BackEndNewDec")
    BackEndUpdateCommit.click()
    waitMoment(3)   
    status =False
    for i in range(len(backendsTable.getRows())):
        if(backendsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("BackEndNewName") ):   
            status = True
            break  
    assertBool(status,"3437")

def STEP_DeleteBackEnd():
    CLBMenu.click()
    backendTab.click()
    heads = backendsTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    for i in range(len(backendsTable.getRows())):
        if(backendsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("BackEndNewName")): 
            actioncell=backendsTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Delete Backend"):
                    button.click()
                    break
            break 
    BackEndRemove.click()
    waitMoment(3)
    if("No items to display." in backendsTable.getCell(0,0).text):
        assertBool(True,"3435")
        return
    status = True
    for i in range(len(backendsTable.getRows())):
        if(backendsTable.getCell(i,columnName).text.strip()==getConfigure_ENG("BackEndNewName") ):   
            status = False
            break
    assertBool(status,"3435")

def STEP_CreateCer():
    CLBMenu.click()
    certificateTab.click()
    certificates_action_create_certificate.click()
    Ceridname.text = getConfigure_ENG("CerName_01")
    Publicidcertificate.text = getConfigure_ENG("CerPublicKey_01")
    Privateidkey.text = getConfigure_ENG("CerPrivateKey_01")
    Ceriddescription.text = getConfigure_ENG("CerDec_01")
    CerCommit.click()
    waitMoment(3)
    status = False
    heads = certificatesTable.getHeads()
    columnName = heads.index('Name')
    for i in range(len(certificatesTable.getRows())):
        if(certificatesTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CerName_01") ):   
            status = True
            break
    assertBool(status,"3441")

def STEP_UpdateCer():
    CLBMenu.click()
    certificateTab.click()
    heads = certificatesTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    for i in range(len(certificatesTable.getRows())):
        if(certificatesTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CerName_01")): 
            actioncell=certificatesTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Update Certificate"):
                    button.click()
                    break
            break 
    
    CerUpdateidname.text = getConfigure_ENG("CerNewName")
    Updateiddescription.text = getConfigure_ENG("CerNewDec")
    UpdateCerCommit.click()
    
    waitMoment(3)
    status = False
    for i in range(len(certificatesTable.getRows())):
        if(certificatesTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CerNewName") ):   
            status = True
            break
    assertBool(status,"3445")
       
def STEP_RemoveCer():
    CLBMenu.click()
    certificateTab.click()
    heads = certificatesTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    for i in range(len(certificatesTable.getRows())):
        if(certificatesTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CerNewName")): 
            actioncell=certificatesTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Delete Certificate"):
                    button.click()
                    break
            break 
    CerRemove.click()
    waitMoment(3)
    if("No items to display." in certificatesTable.getCell(0,0).text):
        assertBool(True,"3443")
        return
    status = True
    for i in range(len(certificatesTable.getRows())):
        if(certificatesTable.getCell(i,columnName).text.strip()==getConfigure_ENG("CerNewName") ):   
            status = False
            break
    assertBool(status,"3443")
    
    
TC_103_NeoCUNetwork  = TestCase("Neocu ENG Network")
TC_103_NeoCUNetwork.AddStep(STEP_AdminLoginAndChangeLanguage)
TC_103_NeoCUNetwork.AddStep(STEP_UserLogin)
TC_103_NeoCUNetwork.AddStep(STEP_createPrivateNet)
TC_103_NeoCUNetwork.AddStep(STEP_EditPrivateNet)
TC_103_NeoCUNetwork.AddStep(STEP_AddSubNet)
 
TC_103_NeoCUNetwork.AddStep(STEP_createRouter)
TC_103_NeoCUNetwork.AddStep(STEP_EditRouter)
TC_103_NeoCUNetwork.AddStep(STEP_ForbidRouter)
TC_103_NeoCUNetwork.AddStep(STEP_StartRouter)
 
TC_103_NeoCUNetwork.AddStep(STEP_ConnectPublicNet)
TC_103_NeoCUNetwork.AddStep(STEP_SetQoS)
TC_103_NeoCUNetwork.AddStep(STEP_DeleteQoS)
TC_103_NeoCUNetwork.AddStep(STEP_DisConnectPublicNet)
 
TC_103_NeoCUNetwork.AddStep(STEP_AddFloatingIP)
TC_103_NeoCUNetwork.AddStep(STEP_FloatingIPSetQoS)
TC_103_NeoCUNetwork.AddStep(STEP_FloatingIPRemoveQoS)
TC_103_NeoCUNetwork.AddStep(STEP_ReleaseFloatingIP)
 
 
TC_103_NeoCUNetwork.AddStep(STEP_AddCLB)
TC_103_NeoCUNetwork.AddStep(STEP_EditCLB)
TC_103_NeoCUNetwork.AddStep(STEP_CLBAddPublicNet)
TC_103_NeoCUNetwork.AddStep(STEP_CLBSetQoS)

TC_103_NeoCUNetwork.AddStep(STEP_CLBAddListener)
# TC_103_NeoCUNetwork.AddStep(STEP_CLBSetQoS)

# TC_103_NeoCUNetwork.AddStep(STEP_CLBRemoveQoS)
# TC_103_NeoCUNetwork.AddStep(STEP_CLBRemovePublicNet)
# TC_103_NeoCUNetwork.AddStep(STEP_RemoveCLB)
 
TC_103_NeoCUNetwork.AddStep(STEP_AddBackEnd)
TC_103_NeoCUNetwork.AddStep(STEP_UpdateBackEnd)
TC_103_NeoCUNetwork.AddStep(STEP_DeleteBackEnd)
TC_103_NeoCUNetwork.AddStep(STEP_CreateCer)
TC_103_NeoCUNetwork.AddStep(STEP_UpdateCer)
TC_103_NeoCUNetwork.AddStep(STEP_RemoveCer)

TC_103_NeoCUNetwork.AddStep(STEP_CLBRemoveQoS)
TC_103_NeoCUNetwork.AddStep(STEP_CLBRemovePublicNet)
TC_103_NeoCUNetwork.AddStep(STEP_RemoveCLB)

TC_103_NeoCUNetwork.AddStep(STEP_DeleteRouter)
TC_103_NeoCUNetwork.AddStep(STEP_deletePriNet)
TC_103_NeoCUNetwork.AddStep(STEP_Clean)


if __name__ == "__main__":
    TC_103_NeoCUNetwork.run()
